﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Abp.Application.Services.Dto;
using Abp.Domain.Repositories;
using Acme.SimpleTaskApp.AppEntities;
using Acme.SimpleTaskApp.Persons.Dto;
using Microsoft.EntityFrameworkCore;

namespace Acme.SimpleTaskApp.Persons
{

    public class PersonAppService : SimpleTaskAppAppServiceBase, IPersonAppService
    {

        private readonly IRepository<Person, Guid> _personRepository;

        public PersonAppService(IRepository<Person, Guid> PersonRepository)
        {
            _personRepository = PersonRepository;
        }


        public async Task<ListResultDto<PersonListDto>> GetAll(GetAllPersonInput input)
        {
            var persons = await _personRepository
                .GetAll()
                .OrderByDescending(t => t.CreationTime)
                .ToListAsync();

            return new ListResultDto<PersonListDto>(
                ObjectMapper.Map<List<PersonListDto>>(persons)
            );
        }
    }
}
